﻿using Abp.Application.Services.Dto;
using Abp.Authorization.Users;
using Abp.Domain.Repositories;
using Abp.Domain.Uow;
using Abp.Linq.Extensions;
using Abp.Organizations;
using Abp.Runtime.Session;
using Abp.UI;
using Camc.Quality.Authorization.Roles;
using Camc.Quality.Authorization.Users;
using Camc.Quality.Authorization.Users.Dto;
using Camc.Quality.Chat;
using Camc.Quality.Common;
using Camc.Quality.Inspection.InspectionManage;
using Camc.Quality.Inspection.InspectionStrat;
using Camc.Quality.IOperationHistory;
using Camc.Quality.ProductionControl;
using Camc.Quality.ProductionPlan;
using Camc.Quality.Quality;
using Camc.Quality.SystemManagement;
using Camc.Quality.WorkFlow;
using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using static Camc.Quality.Inspection.InspectionSeverityDesc;

namespace Camc.Quality.Inspection
{
    public class InspectionStartAppService : QualityAppServiceBase
    {
        private readonly IRepository<InspectionSeverityDesc, Guid> _inspectionSeverityDescRepository;
        private readonly IRepository<InspectionSeverityRole, Guid> _inspectionSeverityRoleRepository;
        private readonly IRepository<InspectionTypeDesc, Guid> _inspectionTypeDescRepository;
        private readonly IRepository<InspectionItemInfo, Guid> _inspectionItemInfoRepository;
        private readonly IRepository<OrganizationUnit, long> _organizationUnitRepository;
        private readonly IRepository<InspectionStandardDesc, Guid> _inspectionStandardDescRepository;
        private readonly RoleManager _roleManager;
        private readonly IRepository<User, long> _userRepository;
        private readonly IRepository<UserRole, long> _userRoleRepository;
        private readonly IOperationHistoryAppService _iOperationHistoryAppService;
        private readonly CodeFormatDescAppService _codeFormatDescAppServiceRepository;
        private readonly WorkFlowAppService _workFlowAppServiceRepository;
        private readonly IRepository<UploadPicture, Guid> _uploadPictureRepository;
        private readonly IUnitOfWorkManager _unitOfWorkManager;
        private readonly IRepository<ProductionScheduler, Guid> _productionSchedulerRepository;
        private readonly IAbpSession _abpSession;
        private readonly IRepository<AffairRemind, int> _affairRemindRepository;
        private readonly InspectionFileCommonService _inspectionFileCommonServiceRepository;


        public InspectionStartAppService(IRepository<InspectionSeverityDesc, Guid> inspectionSeverityDescRepository,
                                 IRepository<InspectionSeverityRole, Guid> inspectionSeverityRoleRepository,
                                 IRepository<InspectionTypeDesc, Guid> inspectionTypeDescRepository,
                                 IRepository<InspectionItemInfo, Guid> inspectionItemInfoRepository,
                                 IRepository<OrganizationUnit, long> organizationUnitRepository,
                                 RoleManager roleManager,
                                 IRepository<InspectionStandardDesc, Guid> inspectionStandardDescRepository,
                                 IRepository<User, long> userRepository,
                                 IRepository<UserRole, long> UserRoleRepository,
                                 CodeFormatDescAppService codeFormatDescAppServiceRepository,
                                 WorkFlowAppService workFlowAppServiceRepository,
                                 IOperationHistoryAppService iOperationHistoryAppService,
                                 IRepository<UploadPicture, Guid> uploadPictureRepository,
                                 IUnitOfWorkManager unitOfWorkManager,
                                 IRepository<ProductionScheduler, Guid> productionSchedulerRepository,
                                 IAbpSession abpSession,
                                 IRepository<AffairRemind, int> affairRemindRepository,
                                 InspectionFileCommonService inspectionFileCommonServiceRepository
                        )
        {
            _inspectionSeverityDescRepository = inspectionSeverityDescRepository;
            _inspectionSeverityRoleRepository = inspectionSeverityRoleRepository;
            _inspectionTypeDescRepository = inspectionTypeDescRepository;
            _inspectionItemInfoRepository = inspectionItemInfoRepository;
            _organizationUnitRepository = organizationUnitRepository;
            _roleManager = roleManager;
            _inspectionStandardDescRepository = inspectionStandardDescRepository;
            _userRepository = userRepository;
            _userRoleRepository = UserRoleRepository;
            _codeFormatDescAppServiceRepository = codeFormatDescAppServiceRepository;
            _workFlowAppServiceRepository = workFlowAppServiceRepository;
            _iOperationHistoryAppService = iOperationHistoryAppService;
            _uploadPictureRepository = uploadPictureRepository;
            _unitOfWorkManager = unitOfWorkManager;
            _productionSchedulerRepository = productionSchedulerRepository;
            _abpSession = abpSession;
            _affairRemindRepository = affairRemindRepository;
            _inspectionFileCommonServiceRepository = inspectionFileCommonServiceRepository;
        }
        /// <summary>
        /// 异常管理页面查询
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task<PagedResultDto<InspectionStandardDescOutDto>> GetInspectionStandardDescList(GetInspectionStandardDescInput input)
        {
            var userList = _userRepository.GetAll().ToList();
            var organizationUnitList = _organizationUnitRepository.GetAll().ToList();
            var rolesList = _roleManager.Roles.ToList();
            var inspectionStardardDesc = from inspectionStandardDesc in _inspectionStandardDescRepository.GetAll()
                                         join inspectionTypeDesc in _inspectionTypeDescRepository.GetAll()
                                         on inspectionStandardDesc.InspectionTypeDescId equals inspectionTypeDesc.Id
                                         join inspectionItemInfo in _inspectionItemInfoRepository.GetAll()
                                         on inspectionStandardDesc.InspectionItemInfoId equals inspectionItemInfo.Id
                                         join inspectionSeverityDesc in _inspectionSeverityDescRepository.GetAll()
                                         on inspectionStandardDesc.InspectionSeverityDescId equals inspectionSeverityDesc.Id
                                         join users in userList on inspectionStandardDesc.CreatorUserId equals users.Id
                                         //into ult
                                         //from a in ult.DefaultIfEmpty()
                                         join role in rolesList
                                         on inspectionItemInfo.RolesId equals role.Id into roled
                                         from rolet in roled.DefaultIfEmpty()
                                         join organizationUnit in organizationUnitList
                                         on inspectionItemInfo.OrganizationUnitsId equals organizationUnit.Id into organizationUnitd
                                         from organizationUnitt in organizationUnitd.DefaultIfEmpty()
                                         join userh in userList
                                         on inspectionStandardDesc.HandlerId equals userh.Id into userhd
                                         from userht in userhd.DefaultIfEmpty()
                                         join userc in userList
                                         on inspectionStandardDesc.ConfirmerId equals userc.Id into usercd
                                         from userct in usercd.DefaultIfEmpty()
                                         select new InspectionStandardDescOutDto
                                         {
                                             Id = inspectionStandardDesc.Id,
                                             Code = inspectionStandardDesc.Code,
                                             TaskCode = inspectionStandardDesc.TaskCode,
                                             TaskCodeId = inspectionStandardDesc.TaskCodeId,
                                             InspectionTypeDescId = inspectionStandardDesc.InspectionTypeDescId,
                                             InspectionTypeDesc = inspectionTypeDesc.TypeName,
                                             InspectionItemInfoId = inspectionStandardDesc.InspectionItemInfoId,
                                             InspectionItemInfo = inspectionItemInfo.ItemName,
                                             InspectionDetails = inspectionStandardDesc.InspectionDetails,
                                             InspectionSeverityDescId = inspectionStandardDesc.InspectionSeverityDescId,
                                             InspectionSeverityDesc = inspectionSeverityDesc.SeverityName,
                                             State = (int)inspectionStandardDesc.State,
                                             Submitter = users.Surname + users.Name,
                                             CreatorUserId = inspectionStandardDesc.CreatorUserId,
                                             CreationTime = inspectionStandardDesc.CreationTime,
                                             Roles = rolet.DisplayName,
                                             RolesId = inspectionItemInfo.RolesId,
                                             OrganizationUnitsId = inspectionItemInfo.OrganizationUnitsId,
                                             OrganizationUnits = organizationUnitt.DisplayName,
                                             HandlerId = inspectionStandardDesc.HandlerId,
                                             Handler = userht.Surname + userht.Name,
                                             CompleteTime = inspectionStandardDesc.CompleteTime,
                                             CauseAnalysis = inspectionStandardDesc.CauseAnalysis,
                                             TreatmentMeasures = inspectionStandardDesc.TreatmentMeasures,
                                             RequestCompleteTime = inspectionStandardDesc.RequestCompleteTime,
                                             CostTime = inspectionStandardDesc.CostTime,
                                             ConfirmerId = inspectionStandardDesc.ConfirmerId,
                                             Confirmer = userct.Surname + userct.Name,
                                             ConfirmTime = inspectionStandardDesc.ConfirmTime,
                                             ConfirmSuggest = inspectionStandardDesc.ConfirmSuggest
                                         };


            if (!string.IsNullOrEmpty(input.TaskCode))
            {
                inspectionStardardDesc = inspectionStardardDesc.Where(d => d.TaskCode.Contains(input.TaskCode));
            }
            if (input.InspectionTypeDescId != null)
            {
                inspectionStardardDesc = inspectionStardardDesc.Where(d => d.InspectionTypeDescId == input.InspectionTypeDescId);
            }
            if (input.InspectionItemInfoId != null)
            {
                inspectionStardardDesc = inspectionStardardDesc.Where(d => d.InspectionItemInfoId == input.InspectionItemInfoId);
            }
            if (input.InspectionSeverityDescId != null)
            {
                inspectionStardardDesc = inspectionStardardDesc.Where(d => d.InspectionSeverityDescId == input.InspectionSeverityDescId);
            }
            if (input.SubmitterId != null)
            {
                inspectionStardardDesc = inspectionStardardDesc.Where(d => d.CreatorUserId == input.SubmitterId);
            }
            if (input.HandlerId != null)
            {
                inspectionStardardDesc = inspectionStardardDesc.Where(d => d.HandlerId == input.HandlerId);
            }
            var count = inspectionStardardDesc.Count();
            inspectionStardardDesc = inspectionStardardDesc.OrderByDescending(e => e.CreationTime).PageBy(input);
            var result = ObjectMapper.Map<List<InspectionStandardDescOutDto>>(inspectionStardardDesc);
            result.ForEach(d =>
            {

                if (input.UserId == d.CreatorUserId)
                {
                    d.Flag = 1;
                }
                else
                {
                    d.Flag = 0;
                }
                //查询上传图片信息
                string url = ConfigHelper.GetAppSetting("App", "GetAppUrl") + "/Inspection/";
                //var flieList = _uploadPictureRepository.GetAll().Where(s => s.BusinessId == d.Id);
                var flieList = (from up in _uploadPictureRepository.GetAll().Where(s => s.BusinessId == d.Id)
                               select new UploadPicture
                               {
                                   Id = up.Id,
                                   CreationTime = up.CreationTime,
                                   CreatorUserId = up.CreatorUserId,
                                   FileName = up.FileName,
                                   FileUrl = url + up.FileName,
                                   Size = up.Size
                               });

                if (flieList != null)
                {
                    var flieResult = ObjectMapper.Map<List<InspectionFileUploadDto>>(flieList.ToList());
                    d.InspectionFileUploadDto = flieResult.ToList();
                }
            });
            return new PagedResultDto<InspectionStandardDescOutDto>(count, result);
        }
        /// <summary>
        /// 任务编号下拉列表
        /// </summary>
        /// <param name="taskCodeStr"></param>
        /// <returns></returns>
        public List<string> GetCodeTaskList(string taskCodeStr)
        {
            if (string.IsNullOrEmpty(taskCodeStr))
            {
                return _inspectionStandardDescRepository.GetAll().Select(p => p.TaskCode).Distinct().Where(d => d != null).ToList();
            }
            else
            {
                return _inspectionStandardDescRepository.GetAll().Where(p => p.TaskCode.Contains(taskCodeStr)).Select(p => p.TaskCode).Distinct().Where(d => d != null).ToList();
            }
        }
        /// <summary>
        /// 一级异常查拉列表
        /// </summary>
        /// <param name="typeNameStr"></param>
        /// <returns></returns>
        public List<InspectionTypeDescDto> GetInspectionTypeDescList(string typeNameStr)
        {
            var inspectionTypeDesc = _inspectionTypeDescRepository.GetAll().Where(d => d != null && d.IsUsed == InspectionTypeDesc.IsUseds.启用);

            if (!string.IsNullOrEmpty(typeNameStr))
            {
                inspectionTypeDesc = inspectionTypeDesc.Where(d => d.TypeName.Contains(typeNameStr)).Distinct();
            }
            var Result = ObjectMapper.Map<List<InspectionTypeDescDto>>(inspectionTypeDesc);
            return Result;

        }
        /// <summary>
        /// 二级异常下拉列表
        /// </summary>
        /// <param name="inspectionTypeDescId"></param>
        /// <param name="itemNameStr"></param>
        /// <returns></returns>
        public List<InspectionItemInfoOutDto> GetInspectionItemInfoList(Guid inspectionTypeDescId, string itemNameStr)
        {
            var inspectionItemInfo = _inspectionItemInfoRepository.GetAll().Where(d => d != null && d.IsUsed == InspectionItemInfo.IsUseds.启用);
            if (inspectionTypeDescId != Guid.Empty)
            {
                inspectionItemInfo = inspectionItemInfo.Where(d => d.TypeId == inspectionTypeDescId);
            }
            if (!string.IsNullOrEmpty(itemNameStr))
            {
                inspectionItemInfo = inspectionItemInfo.Where(d => d.ItemName.Contains(itemNameStr));
            }

            var Result = ObjectMapper.Map<List<InspectionItemInfoOutDto>>(inspectionItemInfo);
            return Result;
        }
        /// <summary>
        /// 异常严重程度下拉列表
        /// </summary>
        /// <param name="severityNameStr"></param>
        /// <returns></returns>
        public List<InspectionSeverityDescOutDto> GetInspectionSeverityDescList(string severityNameStr)
        {
            var severityDesc = _inspectionSeverityDescRepository.GetAll().Where(d => d != null && d.IsUsed == IsUseds.启用);

            if (!string.IsNullOrEmpty(severityNameStr))
            {
                severityDesc = severityDesc.Where(d => d.SeverityName.Contains(severityNameStr)).Distinct();
            }
            var result = ObjectMapper.Map<List<InspectionSeverityDescOutDto>>(severityDesc);
            return result;
        }
        /// <summary>
        /// 提报人下拉列表
        /// </summary>
        /// <returns></returns>
        public List<UserListDto> GetCreateUserList()
        {
            var query = _inspectionStandardDescRepository.GetAll().ToList();
            if (query.Count() > 0)
            {
                var userList = query.Select(s => s.CreatorUserId).Distinct();
                var queryData = from userid in userList
                                join user in _userRepository.GetAll()
                                on userid equals user.Id
                                select new UserListDto
                                {
                                    Id = (long)userid,
                                    Name = user.Surname + user.Name
                                };
                return queryData.ToList();
            }
            return null;
        }
        /// <summary>
        /// 处理人下拉列表
        /// </summary>
        /// <param name="inspectionItemInfoId"></param>
        /// <param name="userNameStr"></param>
        /// <returns></returns>
        public List<UserListDto> GetUserList(Guid inspectionItemInfoId, string userNameStr)
        {
            var userList = _userRepository.GetAll();
            if (inspectionItemInfoId != Guid.Empty)
            {
                var roleId = _inspectionItemInfoRepository.FirstOrDefault(d => d.Id == inspectionItemInfoId).RolesId;
                var queryData = from ul in userList
                                join ur in _userRoleRepository.GetAll()
                                on ul.Id equals ur.UserId
                                where ur.RoleId == roleId
                                select new UserListDto
                                {
                                    Id = ul.Id,
                                    Name = ul.Surname + ul.Name
                                };

                if (!string.IsNullOrEmpty(userNameStr))
                {
                    queryData = queryData.Where(d => d.Name.Contains(userNameStr)).Distinct();
                }
                var result = ObjectMapper.Map<List<UserListDto>>(queryData.ToList());
                return result;
            }
            else
            {
                return null;
            }
        }
        /// <summary>
        /// 异常管理表新增和修改接口，根据是否传输id判断
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task<ResultMessage> CreateOrUpdateInspectionStandardDesc(InspectionStandardDescDto input)
        {
            ResultMessage resultMessage = new ResultMessage();
            if (input.Id == Guid.Empty)
            {
                resultMessage = await CreateInspectionStandardDesc(input);
            }
            else
            {
                resultMessage = await UpdateInspectionStandardDesc(input);
            }
            return resultMessage;
        }
        /// <summary>
        /// 异常管理表新增
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        private async Task<ResultMessage> CreateInspectionStandardDesc(InspectionStandardDescDto input)
        {
            ResultMessage resultMessage = new ResultMessage();
            try
            {
                var code = _codeFormatDescAppServiceRepository.GetCodeFormat("异常管理");
                if (code == null)
                {
                    code = _codeFormatDescAppServiceRepository.GetOrderCode("YCGL", "yyyyMMdd", 1, 5, 1);
                }
                var inspectionStandardDesc = new InspectionStandardDesc()
                {
                    Id = Guid.NewGuid(),
                    Code = code,
                    TaskCode = input.TaskCode,
                    TaskCodeId = input.TaskCodeId,
                    InspectionTypeDescId = input.InspectionTypeDescId,
                    InspectionItemInfoId = input.InspectionItemInfoId,
                    InspectionDetails = input.InspectionDetails,
                    InspectionSeverityDescId = input.InspectionSeverityDescId,
                    State = States.未处理,
                    HandlerId = input.HandlerId,
                    //CompleteTime
                    CauseAnalysis = input.CauseAnalysis,
                    TreatmentMeasures = input.TreatmentMeasures,
                    RequestCompleteTime = input.RequestCompleteTime,
                    //ConfirmerId
                    //ConfirmTime
                    //ConfirmSuggest
                    //CostTime
                };
                var user = _userRepository.FirstOrDefault(s => s.Id == input.UserId);
                var username = user.Surname + user.Name;
                _iOperationHistoryAppService.InsertOperationLog(inspectionStandardDesc.Id, 9, 27, username + "发起了异常");
                //var roseList = _inspectionSeverityRoleRepository.GetAll().Where(s => s.SeverityId == input.InspectionSeverityDescId).Select(s=>s.RoleId);
                //var roleId = string.Join(",", roseList.ToArray());
                var workFlow = _affairRemindRepository.FirstOrDefault(s => s.AffairCode == input.InspectionSeverityDescId.ToString());
                _workFlowAppServiceRepository.SendWorkFlowMessage(input.UserId, null, workFlow.RoleList, inspectionStandardDesc.TaskCode + "发生异常", username + "于" + DateTime.Now + "发起的了异常！", inspectionStandardDesc.Id, MessageSendingMode.SystemToRole, workFlow.Id, false);

                await _inspectionStandardDescRepository.InsertAndGetIdAsync(inspectionStandardDesc);
                foreach (var item in input.InspectionFileUploadDto)
                {
                    var file = _uploadPictureRepository.FirstOrDefault(s => s.Id == item.Id);
                    file.BusinessId = inspectionStandardDesc.Id;
                    //file.Id = inspectionStandardDesc.Id;
                    //await _uploadPictureRepository.InsertAndGetIdAsync(file);
                    //var file = _uploadPictureRepository.FirstOrDefault(s => s.Id == item.Id);
                    //UploadPicture uploadPicture = new UploadPicture()
                    //{
                    //    Id = Guid.NewGuid(),
                    //    BusinessId = inspectionStandardDesc.Id,
                    //    Organization = (Organizations)1,
                    //    Group = (Groups)1,
                    //    FileName = item.FileName,
                    //    FileUrl = item.FileUrl
                    //};
                    //file.BusinessId = input.Id;
                    await _uploadPictureRepository.UpdateAsync(file);
                }
                resultMessage.code = 0;
                return resultMessage;
            }
            catch (Exception ex)
            {
                resultMessage.code = 1;
                resultMessage.Message = ex.Message;
                return resultMessage;
            }
}
        /// <summary>
        /// 异常管理表修改
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        private async Task<ResultMessage> UpdateInspectionStandardDesc(InspectionStandardDescDto input)
        {
            ResultMessage resultMessage = new ResultMessage();
            try
            {
                var userId = GetCurrentUser().Id; //add 11/30
                var inspectionStandardDesc = await _inspectionStandardDescRepository.FirstOrDefaultAsync(d => d.Id == input.Id && d.CreatorUserId == userId);
                if (inspectionStandardDesc != null)
                {
                    inspectionStandardDesc.Code = input.Code;
                    inspectionStandardDesc.TaskCode = input.TaskCode;
                    inspectionStandardDesc.InspectionTypeDescId = input.InspectionTypeDescId;
                    inspectionStandardDesc.InspectionItemInfoId = input.InspectionItemInfoId;
                    inspectionStandardDesc.InspectionDetails = input.InspectionDetails;
                    inspectionStandardDesc.InspectionSeverityDescId = input.InspectionSeverityDescId;
                    inspectionStandardDesc.State = (States)input.State;
                    inspectionStandardDesc.HandlerId = input.HandlerId;
                    //CompleteTime
                    inspectionStandardDesc.CauseAnalysis = input.CauseAnalysis;
                    inspectionStandardDesc.TreatmentMeasures = input.TreatmentMeasures;
                    inspectionStandardDesc.RequestCompleteTime = input.RequestCompleteTime;
                    inspectionStandardDesc.ConfirmTime = input.ConfirmTime;
                    inspectionStandardDesc.ConfirmSuggest = input.ConfirmSuggest;
                    inspectionStandardDesc.CostTime = input.CostTime;
                    var user = _userRepository.FirstOrDefault(s => s.Id == userId);
                    var username = user.Surname + user.Name;
                    if (inspectionStandardDesc.State == States.未处理)
                    {
                        _iOperationHistoryAppService.InsertOperationLog(inspectionStandardDesc.Id, 9, 27, username + "修改了异常");
                        //var roseList = _inspectionSeverityRoleRepository.GetAll().Where(s => s.SeverityId == input.InspectionSeverityDescId).Select(s => s.RoleId);
                        //var roleId = string.Join(",", roseList.ToArray());
                        var workFlow = _affairRemindRepository.FirstOrDefault(s => s.AffairCode == input.InspectionSeverityDescId.ToString());
                        _workFlowAppServiceRepository.SendWorkFlowMessage(userId, null, workFlow.RoleList, inspectionStandardDesc.TaskCode + "发生异常", username + "于" + DateTime.Now + "发起的了异常！", inspectionStandardDesc.Id, MessageSendingMode.UserToRole, workFlow.Id, false);
                    }
                    if (inspectionStandardDesc.State == States.已完成)
                    {
                        inspectionStandardDesc.ConfirmerId = userId;
                        _iOperationHistoryAppService.InsertOperationLog(inspectionStandardDesc.Id, 9, 28, username + "确认了异常");
                    }
                    if (inspectionStandardDesc.State == States.已驳回)
                    {
                        inspectionStandardDesc.ConfirmerId = userId;
                        _iOperationHistoryAppService.InsertOperationLog(inspectionStandardDesc.Id, 9, 29, username + "驳回了异常");
                    }
                    await _inspectionStandardDescRepository.UpdateAsync(inspectionStandardDesc);
                    foreach (var item in input.InspectionFileUploadDto)
                    {
                        var file = _uploadPictureRepository.FirstOrDefault(s => s.Id == item.Id);
                        file.BusinessId = inspectionStandardDesc.Id;
                        await _uploadPictureRepository.UpdateAsync(file);
                    }
                }
                resultMessage.code = 0;
                return resultMessage;
            }
            catch (Exception ex)
            {
                resultMessage.code = 1;
                resultMessage.Message = ex.Message;
                return resultMessage;
            }
        }
        /// <summary>
        /// 异常管理表删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<ResultMessage> DeleteInspectionStandardDesc(Guid id)
        {
            ResultMessage resultMessage = new ResultMessage();
            try
            {
                if (id != Guid.Empty)
                {
                    await _inspectionStandardDescRepository.DeleteAsync(p => p.Id == id);
                }
                resultMessage.code = 0;
                return resultMessage;
            }
            catch (Exception ex)
            {
                resultMessage.code = 1;
                resultMessage.Message = ex.Message;
                return resultMessage;
            }
        }
        /// <summary>
        /// 报工查询接口
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public PagedResultDto<ProductionReportOutput> GetTaskReportList(InputProductionReport input)
        {
            if (input.Id == Guid.NewGuid())
            {
                return null;
            }
            else
            {
                var result = _productionSchedulerRepository.GetAll().Where(d => d.Issue == true)
                .WhereIf(input.Id != null, d => d.Id == input.Id);
                int count = result.Count();
                result = result.PageBy(input);
                var temp = ObjectMapper.Map<List<ProductionReportOutput>>(result);
                return new PagedResultDto<ProductionReportOutput>(count, temp);
            }
        }
    }
}
